package com.rc.saas.tenant.service.ticket;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.mapper.ticket.MemberTicketMapper;
import com.rc.saas.tenant.search.member.MemberTicketSearch;
import com.rc.saas.tenant.vo.ticket.MemberTicketResultVo;
import com.rc.saas.tenant.vo.ticket.MemberTicketVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author frog
 * @date 2021/2/25
 */
@Service
public class MemberTicketServiceImpl implements MemberTicketService {

    @Autowired
    private MemberTicketMapper memberTicketMapper;

    @Override
    public MemberTicketMapper getMapper() {
        return memberTicketMapper;
    }

    @Override
    public PageInfo<MemberTicketResultVo> listPageDetialSendRecord(MemberTicketSearch memberTicketSearch) {
        PageHelper.startPage(memberTicketSearch.getOffset(), memberTicketSearch.getLimit());
        List<MemberTicketResultVo> memberTicketResultVOS = memberTicketMapper.listPageDetialSendRecord(memberTicketSearch);
        return new PageInfo<MemberTicketResultVo>(memberTicketResultVOS);
    }

    @Override
    public PageInfo<MemberTicketVo> listPageMemberTicket(MemberTicketSearch memberTicketSearch) {
        PageHelper.startPage(memberTicketSearch.getOffset(), memberTicketSearch.getLimit());
        List<MemberTicketVo> memberTicketVOList = memberTicketMapper.listPageMemberTicket(memberTicketSearch);
        memberTicketVOList.stream().forEach(vo -> {
            if (vo.getEndTime() != null && vo.getEndTime().before(new Date())) {
                vo.setStatus("2");
            }
        });
        return new PageInfo<>(memberTicketVOList);
    }

    @Override
    public List<MemberTicketVo> exportMemberTicket(MemberTicketSearch memberTicketSearch) {
        List<MemberTicketVo> memberTicketVOList = memberTicketMapper.exportMemberTicket(memberTicketSearch);
        memberTicketVOList.stream().forEach(vo -> {
            if (vo.getEndTime() != null && vo.getEndTime().before(new Date())) {
                vo.setStatus("2");
            }
        });
        return memberTicketVOList;
    }
}
